package com.itheima.controller;

import com.itheima.manager.MovementManager;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MovementController {
    @Autowired
    MovementManager movementManager;

    @PostMapping("/manage/messages/pass")
    public ResponseEntity pass(@RequestBody String[] ids) {
        List<ObjectId> objectIds = new ArrayList<>();
        for (String id : ids) {
            objectIds.add(new ObjectId(id));
        }
        return movementManager.pass(objectIds);
    }

    @PostMapping("/manage/messages/reject")
    public ResponseEntity reject(@RequestBody String[] ids) {
        List<ObjectId> objectIds = new ArrayList<>();
        for (String id : ids) {
            objectIds.add(new ObjectId(id));
        }
        return movementManager.reject(objectIds);
    }
}
